/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.gui.schematy;

import db.models.GrupaOcen;
import java.util.List;
import javax.swing.DefaultListModel;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;

/**
 * Top component which displays something.
 */
@ConvertAsProperties(
        dtd = "-//org.gui.schematy//Scheme//EN",
        autostore = false
)
@TopComponent.Description(
        preferredID = "SchemeTopComponent",
        //iconBase="SET/PATH/TO/ICON/HERE", 
        persistenceType = TopComponent.PERSISTENCE_ALWAYS
)
@TopComponent.Registration(mode = "leftSlidingSide", openAtStartup = false)
@ActionID(category = "Window", id = "org.gui.schematy.SchemeTopComponent")
@ActionReference(path = "Menu/Window" /*, position = 333 */)
@TopComponent.OpenActionRegistration(
        displayName = "#CTL_SchemeAction",
        preferredID = "SchemeTopComponent"
)
@Messages({
    "CTL_SchemeAction=Schematy oceniania",
    "CTL_SchemeTopComponent=Schematy oceniania",
    "HINT_SchemeTopComponent=Okno schematów oceniania"
})
public final class SchemeTopComponent extends TopComponent {

    public SchemeTopComponent() {
        initComponents();
        setName(Bundle.CTL_SchemeTopComponent());
        setToolTipText(Bundle.HINT_SchemeTopComponent());

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        schemeList = new javax.swing.JList();

        setLayout(new java.awt.BorderLayout());

        schemeList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(schemeList);

        add(jScrollPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JList schemeList;
    // End of variables declaration//GEN-END:variables
    @Override
    public void componentOpened() {
        // TODO add custom code on component opening
        DefaultListModel model = new DefaultListModel();
        List<GrupaOcen> listagrupocen = GrupaOcen.getAllGrupaOcen(0);
        for(GrupaOcen g: listagrupocen){
            model.addElement(g.getNazwa());
        }
        schemeList.setModel(model);
    }

    @Override
    public void componentClosed() {
        // TODO add custom code on component closing
    }

    void writeProperties(java.util.Properties p) {
        // better to version settings since initial version as advocated at
        // http://wiki.apidesign.org/wiki/PropertyFiles
        p.setProperty("version", "1.0");
        // TODO store your settings
    }

    void readProperties(java.util.Properties p) {
        String version = p.getProperty("version");
        // TODO read your settings according to their version
    }
}
